package com.sdp.irrigation.db.irrigation_emp_field.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.core.bizc.db.IViewQuery;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.irrigation.db.irrigation_emp_field.mapper.IrrigationEmpFieldMapper;
import com.sdp.irrigation.db.irrigation_emp_field.service.IIrrigationEmpFieldService;
import com.sdp.irrigation.entity.IrrigationEmpField;

/**
 * <p>
 * 人员田块信息 服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-12-22
 */
@Service
public class IrrigationEmpFieldServiceImpl extends ServiceImpl<IrrigationEmpFieldMapper, IrrigationEmpField> implements IIrrigationEmpFieldService,IViewQuery{

	@Autowired
	private IrrigationEmpFieldMapper irrigationEmpFieldMapper;
	
	@Override
	public void removeEmpFieldByEmpNo(String projectNo,String empNo) {
		LambdaQueryWrapper<IrrigationEmpField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(IrrigationEmpField::getEmpNo, empNo);
		lambdaQueryWrapper.eq(IrrigationEmpField::getProjectNo, projectNo);
		remove(lambdaQueryWrapper);
		
	}

	@Override
	public List<String> queryEmpFieldNodeKeys(String projectNo, String empNo) {
		LambdaQueryWrapper<IrrigationEmpField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(IrrigationEmpField::getEmpNo, empNo);
		lambdaQueryWrapper.eq(IrrigationEmpField::getProjectNo, projectNo);
		List<IrrigationEmpField> empFieldList = list(lambdaQueryWrapper);
		List<String> nodeKeys = new ArrayList<>();
		for(IrrigationEmpField field : empFieldList) {
			nodeKeys.add(field.getNodeKey());
		}
		return nodeKeys;
	}

	@Override
	public <T> List<T> viewList(QueryWrapper<T> queryWrapper,DataCenter dc) {
		return irrigationEmpFieldMapper.viewList(queryWrapper,dc);
	}

	@Override
	public <T> int viewCount(QueryWrapper<T> queryWrapper) {
		return irrigationEmpFieldMapper.viewCount(queryWrapper);
	}

	@Override
	public <T> IPage<T> viewPage(IPage<T> page, QueryWrapper<T> queryWrapper,DataCenter dc) {
		return irrigationEmpFieldMapper.viewPage(page, queryWrapper,dc);
	}

	@Override
	public List<String> queryEmpProjectNos(String empNo) {
		LambdaQueryWrapper<IrrigationEmpField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(IrrigationEmpField::getEmpNo, empNo);
		List<IrrigationEmpField> empFieldList = list(lambdaQueryWrapper);
		List<String> projectNos = new ArrayList<>();
		for(IrrigationEmpField field : empFieldList) {
			projectNos.add(field.getProjectNo());
		}
		return projectNos;
	}

}
